/* ------------------------------------------------------------------------*
 *
 * ------------------------------------------------------------------------*/
#include "com_hal.h"
#include "wifi_hal.h"
#include "comtask.h"
#include "wifitask.h"
#include "osObjects.h"   
#include "cominfo.h"



void CmdProc(void);
void ComStringHandle(void);

uint8_t TimeOutInfo[] = "Time Out !\0";


/*****************************************************************************//*!
* @brief   	com task init .
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
uint32_t Flag;
void ComTask(void const *argument) {
    
    
    ComInit(115200, COM_PAR_NONE);
    
    for(;;){
        Flag = osThreadFlagsWait(0x03,osFlagsWaitAny,500);

        if (Flag & osFlagsError) {
            //if(osFlagsErrorTimeout == Flag)
                //ComStringSend("Timer out 500ms, flag time\r\n");
        }
        
        osDelay(500);
        //ComStringSend("Timer out 500ms, delay time\r\n");
    }
}

/*****************************************************************************//*!
* @brief   	String Handle .
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/

void ComStringHandle(void) {
    ComRcvSt = COM_RX_IDLE;

    //WifiDataSend(ComBuff, ComRcvCnt);
    ComRcvCnt = 0;

    ComRcvSt = COM_RX_IDLE;
}

/*****************************************************************************//*!
* @brief   	Data Handle .
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/

void ComDataHandle(void) {

}

/*****************************************************************************//*!
* @brief   Command Proc .
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/

void CmdProc() {
    uint8_t Cnt;

    if (CMD_START != ComBuff[0])
        return;

    switch (ComBuff[1]) {
        case 'T': Cnt = 0;
            while (ComInfo[COM_INFO_TEST][Cnt]) {
                ComBuff[Cnt] = ComInfo[COM_INFO_TEST][Cnt];
                Cnt++;
            }
            ComBuff[Cnt] = 0;
            ComStringSend(ComBuff);
            break;
        case 'V': Cnt = 0;
            while (ComInfo[COM_INFO_VER][Cnt]) {
                ComBuff[Cnt] = ComInfo[COM_INFO_VER][Cnt];
                Cnt++;
            }
            ComBuff[Cnt] = 0;
            ComStringSend(ComBuff);
            break;
        default: break;
    }
}
